<template>
  <div class="rank">
    <h4 class="title">{{ title }}</h4>
    <ul class="list" :style="{height:height?`${height}px`:'auto',overflow:'auto'}">
      <li :key="index" v-for="(item, index) in list">
        <span :class="index < 3 ? 'active' : null">{{ index + 1 }}</span>
        <span :class="getClasses(index)">{{ item.name }}</span>
        <!--<span >{{ item.name }}</span>-->
        <span>{{ item.total }}</span>
      </li>
    </ul>
  </div>
</template>

<script>
  export default {
    name: "RankList",
    // ['title', 'list']
    props: {
      title: {
        type: String,
        default: ''
      },
      list: {
        type: Array,
        default: null
      },
      height: {
        type: Number,
        default: null
      }
    },
    methods: {
      getClasses(index) {
        // 根据索引返回一个对象
        return {
          'Ranking1': index === 0, // 第一名
          'Ranking2': index === 1, // 第二名
          'Ranking3': index === 2, // 第三名
          // 可以继续添加更多的类名和条件判断
        };
      }
    }
  }
</script>

<style lang="less" scoped>

  .rank {
    padding: 0 32px 32px 72px;

    .list {
      margin: 25px 0 0;
      padding: 0;
      list-style: none;

      li {
        margin-top: 16px;

        span {
          color: #606266;
          font-size: 14px;
          line-height: 22px;

          &:first-child {
            background-color: #f5f5f5;
            border-radius: 20px;
            display: inline-block;
            font-size: 12px;
            font-weight: 600;
            margin-right: 24px;
            height: 20px;
            line-height: 20px;
            width: 30px;
            text-align: center;
          }
          &.active {
            width: 30px;
            /*margin: auto;*/
            background: url(https://chs.newrank.cn/main/rank/bg-rank-index.png) no-repeat 50%;
            font-size: 14px;
            color: #fff;
            background-size: cover;
            line-height: 30px;
            height: 34px;
          }
          &.Ranking1 {
            color: #ff3b00;
            font-size: 20px;
          } &.Ranking2 {
            color: #e6af00;
            font-size: 18px;
          } &.Ranking3 {
            color: #e6af00;
            font-size: 16px;
          }
          &:last-child {
            float: right;
          }
        }
      }
    }
  }

  .mobile .rank {
    padding: 0 32px 32px 32px;
  }

</style>